package com.yuan.common.date;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtil {

	public static String format(Date date, String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}

	/**
	 * Returns current date as String in format dd/MM/yyyy
	 * 
	 * @return String in format dd/MM/yyyy representing current date
	 */
	public static String getPresentDate() {
		return getDateFormat_ddMMyyyy(GregorianCalendar.getInstance());
	}

	/**
	 * Returns current date as String in format yyyyMMdd
	 * 
	 * @return String in format yyyyMMdd representing current date
	 */
	public static String getPresentDateFormat_yyyyMMdd() {
		DecimalFormat df = new DecimalFormat("00");
		Calendar date = GregorianCalendar.getInstance();
		return date.get(Calendar.YEAR) + df.format(date.get(Calendar.MONTH) + 1) + df.format(date.get(Calendar.DAY_OF_MONTH));
	}

	/**
	 * Returns calendar parameter as date in format dd/MM/yyyy
	 * 
	 * @param calendar
	 * @return String representing date in format dd/MM/yyyy
	 */
	public static String getDateFormat_ddMMyyyy(Calendar calendar) {
		DecimalFormat df = new DecimalFormat("00");
		return df.format(calendar.get(Calendar.DAY_OF_MONTH)) + "/" + df.format(calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.YEAR);
	}

}
